
//
//  CTTabbarViewController.m
//  百思不得姐
//
//  Created by leo on 2017/5/19.
//  Copyright © 2017年 mine.com. All rights reserved.
//

#import "CTTabbarViewController.h"
#import "CTEssenceViewController.h"
#import "CTFriendTrendViewController.h"
#import "CTNewViewController.h"
#import "CTMETableViewController.h"
#import "CTPublishViewController.h"
#import "UIImage+ctImage.h"


@interface CTTabbarViewController ()

@end

@implementation CTTabbarViewController

+ (void)load {
    //设置tabbar字体
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *attributeText = [NSMutableDictionary dictionary];
    attributeText[NSForegroundColorAttributeName] = [UIColor blackColor];
//    attributeText[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:attributeText forState:UIControlStateSelected];
    //
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:attr forState:UIControlStateNormal];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAllChildViewControllrs];
    [self setPublishButton];
}
- (void)setAllChildViewControllrs {
    //
    CTEssenceViewController *essenceVc = [[CTEssenceViewController alloc] init];
    [self addOneChildViewController:essenceVc normalImage:[UIImage imageWithOriginalRenderImage:@"tabBar_essence_icon"] highImage:[UIImage imageWithOriginalRenderImage:@"tabBar_essence_click_icon"] title:@"精华"];
    //
    CTNewViewController *newVc = [[CTNewViewController alloc] init];
    [self addOneChildViewController:newVc normalImage:[UIImage imageWithOriginalRenderImage:@"tabBar_new_icon"] highImage:[UIImage imageWithOriginalRenderImage:@"tabBar_new_click_icon"] title:@"新帖"];
    //
    CTPublishViewController *pubVc = [[CTPublishViewController alloc] init];
    [self addOneChildViewController:pubVc normalImage:nil highImage:nil title:nil];
//    pubVc.tabBarItem.enabled = NO;
    //
    CTFriendTrendViewController *friendTrendVc = [[CTFriendTrendViewController alloc] init];
    [self addOneChildViewController:friendTrendVc normalImage:[UIImage imageWithOriginalRenderImage:@"tabBar_friendTrends_icon"] highImage:[UIImage imageWithOriginalRenderImage:@"tabBar_friendTrends_click_icon"] title:@"关注"];
    //
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MeTableViewController" bundle:nil];
    CTMETableViewController *meVc = [storyboard instantiateInitialViewController];
    [self addOneChildViewController:meVc normalImage:[UIImage imageNamed:@"tabBar_me_icon"] highImage:[UIImage imageNamed:@"tabBar_me_click_icon"] title:@"我的"];
}

#pragma mark - publishBtn 发布
- (void)setPublishButton {
    UIButton *publishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [publishBtn setImage:[UIImage imageWithOriginalRenderImage:@"tabBar_publish_icon"] forState:UIControlStateNormal];
    [publishBtn setImage:[UIImage imageWithOriginalRenderImage:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
    [publishBtn sizeToFit];
    publishBtn.center = CGPointMake(self.tabBar.frame.size.width * 0.5, self.tabBar.frame.size.height * 0.5);
    [publishBtn addTarget:self action:@selector(clickPublishBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:publishBtn];
}
- (void)clickPublishBtn {
    NSLog(@"点击了发布按钮");
}
#pragma mark - 添加一个子控制器
- (void)addOneChildViewController:(UIViewController *)viewController normalImage:(UIImage *)normalImage highImage:(UIImage *)highImage title:(NSString *)title{
    viewController.tabBarItem.image = normalImage;
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.selectedImage = highImage;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self addChildViewController:nav];

    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
